package com.zhaohanlin.start;

import org.junit.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zhaohanlin
 */

public class ListTest {
    @Test
    public void build() {
        List<String> arrayList = new ArrayList<>();
        arrayList.add("日本");
        arrayList.add("法兰西");
        arrayList.add("德意志");
        arrayList.add("德国");
        arrayList.add(0, "法国");
        arrayList.set(0, "中国");
        for (String e : arrayList) {
            System.out.println(e);
        }
        if (arrayList.contains("日本")) {
            arrayList.remove("日本");

        }
        for (String e : arrayList) {
            System.out.println(e);
        }
        arrayList.remove("德国");
        for (String e : arrayList) {
            System.out.println(e);
        }
        System.out.println(arrayList);
        arrayList.clear();
        System.out.println(arrayList.isEmpty() ? "list是：" : "list不是");
        List<String> countries = List.of("中国，美国，俄罗斯，日本");
        Object[] countriesArr = countries.toArray();
        System.out.println(Arrays.toString(countriesArr));
    }

    @Test
    public void list() {
//快速创建一个List
        List<String> coumtries = List.of("中国", "日本", "法国", "美国");
//将List砖成数组（只能转成object数组）
        Object[] coumtriesArr = coumtries.toArray();
        System.out.println(Arrays.toString(coumtriesArr));

    }
}